package reflect;

import java.lang.reflect.Field;

public class ReflectDemo8 {
    public static void main(String[] args)  throws Exception{
        Teacher teacher = new Teacher();
        teacher.name= "张三";//通常用teacher.setName("张三");
        Class cls =Class.forName("reflect.Teacher");
        Object obj = cls.newInstance();
        Field field = cls.getField("name");
        field.set(obj,"张三");
        System.out.println(obj);
        Object o2 = field.get(obj);
    System.out.println(o2);
    }
}
